/*
 * MainClientView.java
 *
 * Created on Feb 14, 2011, 12:03:36 PM
 */
package mainpackage;

import java.awt.event.KeyEvent;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;

/**
 * @author Taylor Rose
 * @author L.A.W.
 * @author Eric Kisner
 */
public class MainClientView extends javax.swing.JFrame {

    private int selectedPlayerId;
    private String selectedTeamName;
    private int selectedGameId;
    private MainViewHandler handler;
    private final DatabaseConnection conn = DatabaseConnection.instance();

    /** Creates new form MainClientView */
    public MainClientView() {
        this.handler = new MainViewHandler( this );
        initComponents();
        initChangeListener();
    }

    private void setSelectedGameId( int selectedGameId ) {
        this.selectedGameId = selectedGameId;
    }

    private void setSelectedPlayerId( int selectedPlayerId ) {
        this.selectedPlayerId = selectedPlayerId;
    }

    private void setSelectedTeamName( String selectedTeamName ) {
        this.selectedTeamName = selectedTeamName;
    }

    /**
     * Add a ChangeListener to the TabbedPane to listen to any Tab selection changes.
     */
    private void initChangeListener() {
        jTabbedPane1.addChangeListener( new ChangeListener() {

            public void stateChanged( ChangeEvent e ) {
                JTabbedPane pane = (JTabbedPane) e.getSource();
                String selectedTitle = pane.getTitleAt( pane.getSelectedIndex() );
                char firstLetter = selectedTitle.toLowerCase().charAt( 0 );
                handler.resetFields( firstLetter );
            }
        } );
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings( "unchecked" )
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        playerTab = new javax.swing.JPanel();
        playerActionsHolder = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        searchPlayerField = new javax.swing.JTextField();
        searchPlayerButton = new javax.swing.JButton();
        addPlayerButton = new javax.swing.JButton();
        playerTableHolder = new javax.swing.JPanel();
        fieldsHolder = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        playerNameField = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        teamNameField = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        heightField = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        goalsScoredField = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        hometownField = new javax.swing.JTextField();
        teamsTab = new javax.swing.JPanel();
        teamActionsHolder = new javax.swing.JPanel();
        jLabel13 = new javax.swing.JLabel();
        searchTeamField = new javax.swing.JTextField();
        searchTeamButton = new javax.swing.JButton();
        addTeamButton = new javax.swing.JButton();
        teamTableHolder = new javax.swing.JPanel();
        fieldsHolder2 = new javax.swing.JPanel();
        jPanel8 = new javax.swing.JPanel();
        jLabel14 = new javax.swing.JLabel();
        teamNameField2 = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        divisionNameField = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        conferenceNameField = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        homeArenaNameField = new javax.swing.JTextField();
        jPanel9 = new javax.swing.JPanel();
        jLabel20 = new javax.swing.JLabel();
        teamGoalsScoredField = new javax.swing.JTextField();
        jLabel21 = new javax.swing.JLabel();
        teamGoalsScoredAgainstField = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        overtimeWinsField = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        pointsField = new javax.swing.JTextField();
        jLabel25 = new javax.swing.JLabel();
        totalLossesField = new javax.swing.JTextField();
        jLabel26 = new javax.swing.JLabel();
        totalWinsField = new javax.swing.JTextField();
        gamesTab = new javax.swing.JPanel();
        gameActionsHolder = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        searchGameField = new javax.swing.JTextField();
        searchGameButton = new javax.swing.JButton();
        addGameButton = new javax.swing.JButton();
        jLabel27 = new javax.swing.JLabel();
        gameTableHolder = new javax.swing.JPanel();
        fieldsHolder1 = new javax.swing.JPanel();
        jPanel10 = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        awayTeamNameField = new javax.swing.JTextField();
        jLabel22 = new javax.swing.JLabel();
        homeTeamNameField = new javax.swing.JTextField();
        jLabel23 = new javax.swing.JLabel();
        hostArenaNameField = new javax.swing.JTextField();
        jLabel24 = new javax.swing.JLabel();
        gameDatePlayedField = new javax.swing.JTextField();
        jPanel7 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        winnerTeamNameField = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        loserTeamNameField = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        winnerScoreField = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        loserScoreField = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        playerActionsHolder.setLayout(null);

        jLabel1.setText("Enter Player Name:");
        playerActionsHolder.add(jLabel1);
        jLabel1.setBounds(10, 20, 110, 14);

        searchPlayerField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                searchPlayerFieldKeyTyped(evt);
            }
        });
        playerActionsHolder.add(searchPlayerField);
        searchPlayerField.setBounds(125, 17, 130, 20);

        searchPlayerButton.setText("Search for Players");
        searchPlayerButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchPlayerButtonActionPerformed(evt);
            }
        });
        playerActionsHolder.add(searchPlayerButton);
        searchPlayerButton.setBounds(270, 16, 140, 23);

        deletePlayerButton.setText("Delete Player");
        deletePlayerButton.setEnabled(false);
        deletePlayerButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deletePlayerButtonActionPerformed(evt);
            }
        });
        playerActionsHolder.add(deletePlayerButton);
        deletePlayerButton.setBounds(420, 16, 110, 23);

        updatePlayerButton.setText("Update Player");
        updatePlayerButton.setEnabled(false);
        updatePlayerButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                updatePlayerButtonActionPerformed(evt);
            }
        });
        playerActionsHolder.add(updatePlayerButton);
        updatePlayerButton.setBounds(545, 16, 120, 23);

        addPlayerButton.setText("Add Player");
        addPlayerButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addPlayerButtonActionPerformed(evt);
            }
        });
        playerActionsHolder.add(addPlayerButton);
        addPlayerButton.setBounds(680, 16, 100, 23);

        playerTableHolder.setLayout(null);

        jPanel6.setLayout(new java.awt.GridLayout(5, 2, 0, 20));

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("Player Name:");
        jPanel6.add(jLabel2);

        playerNameField.setFont(new java.awt.Font("Tahoma", 0, 14));
        jPanel6.add(playerNameField);

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel3.setText("Team Name:");
        jPanel6.add(jLabel3);

        teamNameField.setFont(playerNameField.getFont());
        jPanel6.add(teamNameField);

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel4.setText("Height:");
        jPanel6.add(jLabel4);

        heightField.setFont(playerNameField.getFont());
        jPanel6.add(heightField);

        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel5.setText("Total Goals Scored:");
        jPanel6.add(jLabel5);

        goalsScoredField.setFont(playerNameField.getFont());
        jPanel6.add(goalsScoredField);

        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel6.setText("Country:");
        jPanel6.add(jLabel6);

        hometownField.setFont(playerNameField.getFont());
        jPanel6.add(hometownField);

        javax.swing.GroupLayout fieldsHolderLayout = new javax.swing.GroupLayout(fieldsHolder);
        fieldsHolder.setLayout(fieldsHolderLayout);
        fieldsHolderLayout.setHorizontalGroup(
            fieldsHolderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(fieldsHolderLayout.createSequentialGroup()
                .addGap(186, 186, 186)
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, 379, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(221, Short.MAX_VALUE))
        );
        fieldsHolderLayout.setVerticalGroup(
            fieldsHolderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(fieldsHolderLayout.createSequentialGroup()
                .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, 240, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout playerTabLayout = new javax.swing.GroupLayout(playerTab);
        playerTab.setLayout(playerTabLayout);
        playerTabLayout.setHorizontalGroup(
            playerTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(playerTabLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(playerTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(playerTabLayout.createSequentialGroup()
                        .addComponent(playerTableHolder, javax.swing.GroupLayout.DEFAULT_SIZE, 786, Short.MAX_VALUE)
                        .addContainerGap())
                    .addComponent(playerActionsHolder, javax.swing.GroupLayout.DEFAULT_SIZE, 796, Short.MAX_VALUE)
                    .addGroup(playerTabLayout.createSequentialGroup()
                        .addComponent(fieldsHolder, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        playerTabLayout.setVerticalGroup(
            playerTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(playerTabLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(playerActionsHolder, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(playerTableHolder, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(fieldsHolder, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Players", playerTab);

        teamActionsHolder.setLayout(null);

        jLabel13.setText("Enter Team  Name:");
        teamActionsHolder.add(jLabel13);
        jLabel13.setBounds(10, 20, 110, 14);

        searchTeamField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                searchTeamFieldKeyTyped(evt);
            }
        });
        teamActionsHolder.add(searchTeamField);
        searchTeamField.setBounds(130, 17, 130, 20);

        searchTeamButton.setText("Search for Teams");
        searchTeamButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchTeamButtonActionPerformed(evt);
            }
        });
        teamActionsHolder.add(searchTeamButton);
        searchTeamButton.setBounds(274, 16, 140, 23);

        deleteTeamButton.setText("Delete Team");
        deleteTeamButton.setEnabled(false);
        deleteTeamButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteTeamButtonActionPerformed(evt);
            }
        });
        teamActionsHolder.add(deleteTeamButton);
        deleteTeamButton.setBounds(430, 16, 110, 23);

        updateTeamButton.setText("Update Team");
        updateTeamButton.setEnabled(false);
        updateTeamButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                updateTeamButtonActionPerformed(evt);
            }
        });
        teamActionsHolder.add(updateTeamButton);
        updateTeamButton.setBounds(555, 16, 110, 23);

        addTeamButton.setText("Add Team");
        addTeamButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addTeamButtonActionPerformed(evt);
            }
        });
        teamActionsHolder.add(addTeamButton);
        addTeamButton.setBounds(680, 16, 100, 23);

        teamTableHolder.setLayout(null);

        jPanel8.setLayout(new java.awt.GridLayout(5, 2, 0, 20));

        jLabel14.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel14.setText("Team Name:");
        jPanel8.add(jLabel14);

        teamNameField2.setFont(playerNameField.getFont());
        jPanel8.add(teamNameField2);

        jLabel15.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel15.setText("Division Name:");
        jPanel8.add(jLabel15);

        divisionNameField.setFont(playerNameField.getFont());
        jPanel8.add(divisionNameField);

        jLabel16.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel16.setText("Conference Name:");
        jPanel8.add(jLabel16);

        conferenceNameField.setFont(playerNameField.getFont());
        jPanel8.add(conferenceNameField);

        jLabel19.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel19.setText("Home Arena Name:");
        jPanel8.add(jLabel19);

        homeArenaNameField.setFont(playerNameField.getFont());
        jPanel8.add(homeArenaNameField);

        jPanel9.setLayout(new java.awt.GridLayout(6, 2, 0, 20));

        jLabel20.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel20.setText("Goals Scored:");
        jPanel9.add(jLabel20);

        teamGoalsScoredField.setFont(playerNameField.getFont());
        jPanel9.add(teamGoalsScoredField);

        jLabel21.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel21.setText("Goals Scored Against:");
        jPanel9.add(jLabel21);

        teamGoalsScoredAgainstField.setFont(playerNameField.getFont());
        jPanel9.add(teamGoalsScoredAgainstField);

        jLabel17.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel17.setText("Overtime Wins:");
        jPanel9.add(jLabel17);

        overtimeWinsField.setFont(playerNameField.getFont());
        jPanel9.add(overtimeWinsField);

        jLabel18.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel18.setText("Points:");
        jPanel9.add(jLabel18);

        pointsField.setFont(playerNameField.getFont());
        jPanel9.add(pointsField);

        jLabel25.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel25.setText("Total Losses:");
        jPanel9.add(jLabel25);

        totalLossesField.setFont(playerNameField.getFont());
        jPanel9.add(totalLossesField);

        jLabel26.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel26.setText("Total Wins:");
        jPanel9.add(jLabel26);

        totalWinsField.setFont(playerNameField.getFont());
        jPanel9.add(totalWinsField);

        javax.swing.GroupLayout fieldsHolder2Layout = new javax.swing.GroupLayout(fieldsHolder2);
        fieldsHolder2.setLayout(fieldsHolder2Layout);
        fieldsHolder2Layout.setHorizontalGroup(
            fieldsHolder2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(fieldsHolder2Layout.createSequentialGroup()
                .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, 379, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, 379, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        fieldsHolder2Layout.setVerticalGroup(
            fieldsHolder2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, 261, Short.MAX_VALUE)
            .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, 261, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout teamsTabLayout = new javax.swing.GroupLayout(teamsTab);
        teamsTab.setLayout(teamsTabLayout);
        teamsTabLayout.setHorizontalGroup(
            teamsTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(teamsTabLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(teamsTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(teamsTabLayout.createSequentialGroup()
                        .addComponent(teamTableHolder, javax.swing.GroupLayout.DEFAULT_SIZE, 786, Short.MAX_VALUE)
                        .addContainerGap())
                    .addComponent(teamActionsHolder, javax.swing.GroupLayout.DEFAULT_SIZE, 796, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, teamsTabLayout.createSequentialGroup()
                        .addComponent(fieldsHolder2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        teamsTabLayout.setVerticalGroup(
            teamsTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(teamsTabLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(teamActionsHolder, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(teamTableHolder, javax.swing.GroupLayout.PREFERRED_SIZE, 194, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(fieldsHolder2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Teams", teamsTab);

        gameActionsHolder.setLayout(null);

        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel7.setText("Enter Game Date");
        gameActionsHolder.add(jLabel7);
        jLabel7.setBounds(10, 10, 100, 14);

        searchGameField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                searchGameFieldKeyTyped(evt);
            }
        });
        gameActionsHolder.add(searchGameField);
        searchGameField.setBounds(130, 17, 130, 20);

        searchGameButton.setText("Search for Games");
        searchGameButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchGameButtonActionPerformed(evt);
            }
        });
        gameActionsHolder.add(searchGameButton);
        searchGameButton.setBounds(275, 16, 140, 23);

        deleteGameButton.setText("Delete Game");
        deleteGameButton.setEnabled(false);
        deleteGameButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteGameButtonActionPerformed(evt);
            }
        });
        gameActionsHolder.add(deleteGameButton);
        deleteGameButton.setBounds(435, 16, 110, 23);

        updateGameButton.setText("Update Game");
        updateGameButton.setEnabled(false);
        updateGameButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                updateGameButtonActionPerformed(evt);
            }
        });
        gameActionsHolder.add(updateGameButton);
        updateGameButton.setBounds(560, 16, 110, 23);

        addGameButton.setText("Add Game");
        addGameButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addGameButtonActionPerformed(evt);
            }
        });
        gameActionsHolder.add(addGameButton);
        addGameButton.setBounds(681, 16, 100, 23);

        jLabel27.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel27.setText("or Team Name");
        gameActionsHolder.add(jLabel27);
        jLabel27.setBounds(10, 30, 100, 14);

        gameTableHolder.setLayout(null);

        jPanel10.setLayout(new java.awt.GridLayout(5, 2, 0, 20));

        jLabel12.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel12.setText("Away Team Name:");
        jPanel10.add(jLabel12);

        awayTeamNameField.setFont(playerNameField.getFont());
        jPanel10.add(awayTeamNameField);

        jLabel22.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel22.setText("Home Team Name:");
        jPanel10.add(jLabel22);

        homeTeamNameField.setFont(playerNameField.getFont());
        jPanel10.add(homeTeamNameField);

        jLabel23.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel23.setText("Host Arena Name:");
        jPanel10.add(jLabel23);

        hostArenaNameField.setFont(playerNameField.getFont());
        jPanel10.add(hostArenaNameField);

        jLabel24.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel24.setText("Date Played:");
        jPanel10.add(jLabel24);

        gameDatePlayedField.setFont(playerNameField.getFont());
        jPanel10.add(gameDatePlayedField);

        jPanel7.setLayout(new java.awt.GridLayout(5, 2, 0, 20));

        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel8.setText("Winner Team Name:");
        jPanel7.add(jLabel8);

        winnerTeamNameField.setFont(playerNameField.getFont());
        jPanel7.add(winnerTeamNameField);

        jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel9.setText("Loser Team Name:");
        jPanel7.add(jLabel9);

        loserTeamNameField.setFont(playerNameField.getFont());
        jPanel7.add(loserTeamNameField);

        jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel10.setText("Winner Score:");
        jPanel7.add(jLabel10);

        winnerScoreField.setFont(playerNameField.getFont());
        jPanel7.add(winnerScoreField);

        jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel11.setText("Loser Score:");
        jPanel7.add(jLabel11);

        loserScoreField.setFont(playerNameField.getFont());
        jPanel7.add(loserScoreField);

        javax.swing.GroupLayout fieldsHolder1Layout = new javax.swing.GroupLayout(fieldsHolder1);
        fieldsHolder1.setLayout(fieldsHolder1Layout);
        fieldsHolder1Layout.setHorizontalGroup(
            fieldsHolder1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(fieldsHolder1Layout.createSequentialGroup()
                .addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE, 389, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, 379, Short.MAX_VALUE)
                .addContainerGap())
        );
        fieldsHolder1Layout.setVerticalGroup(
            fieldsHolder1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel10, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 259, Short.MAX_VALUE)
            .addComponent(jPanel7, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 259, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout gamesTabLayout = new javax.swing.GroupLayout(gamesTab);
        gamesTab.setLayout(gamesTabLayout);
        gamesTabLayout.setHorizontalGroup(
            gamesTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gamesTabLayout.createSequentialGroup()
                .addComponent(fieldsHolder1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(gamesTabLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(gamesTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(gamesTabLayout.createSequentialGroup()
                        .addComponent(gameTableHolder, javax.swing.GroupLayout.DEFAULT_SIZE, 786, Short.MAX_VALUE)
                        .addGap(10, 10, 10))
                    .addComponent(gameActionsHolder, javax.swing.GroupLayout.DEFAULT_SIZE, 796, Short.MAX_VALUE)))
        );
        gamesTabLayout.setVerticalGroup(
            gamesTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gamesTabLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(gameActionsHolder, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(gameTableHolder, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(fieldsHolder1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Games", gamesTab);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 811, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 588, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void searchPlayerFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_searchPlayerFieldKeyTyped
        if( evt.getKeyCode() == KeyEvent.VK_ENTER ) {
            searchPlayer();
        }
    }//GEN-LAST:event_searchPlayerFieldKeyTyped

    private void searchTeamFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_searchTeamFieldKeyTyped
        if( evt.getKeyCode() == KeyEvent.VK_ENTER ) {
            searchTeam();
        }
    }//GEN-LAST:event_searchTeamFieldKeyTyped

    private void searchGameFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_searchGameFieldKeyTyped
        if( evt.getKeyCode() == KeyEvent.VK_ENTER ) {
            searchGame();
        }
    }//GEN-LAST:event_searchGameFieldKeyTyped

    private void searchPlayerButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchPlayerButtonActionPerformed
        handler.resetAll( 'p' );
        searchPlayer();
    }//GEN-LAST:event_searchPlayerButtonActionPerformed

    private void searchTeamButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchTeamButtonActionPerformed
        handler.resetAll( 't' );
        searchTeam();
    }//GEN-LAST:event_searchTeamButtonActionPerformed

    private void searchGameButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchGameButtonActionPerformed
        handler.resetAll( 'g' );
        searchGame();
    }//GEN-LAST:event_searchGameButtonActionPerformed

    private void deleteTeamButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteTeamButtonActionPerformed
        if( !confirmAction( "team", true ) ) {
            return;
        }

        int teamId = -1;
        String sql = "SELECT team_id FROM team WHERE team_name = '" + selectedTeamName + "'";
        try {
            ResultSet rs = conn.executeQuery( sql );
            if( rs.next() ) {
                teamId = rs.getInt( "team_id" );
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error retrieving team information.", null );
        }

        int arenaId = -1;
        sql = "SELECT arena_id FROM playsat WHERE team_id = " + teamId;
        try {
            ResultSet rs = conn.executeQuery( sql );
            if( rs.next() ) {
                arenaId = rs.getInt( "arena_id" );
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error selecting arena", null );
            return;
        }

        String gameIdSQL = "SELECT game_id FROM game NATURAL JOIN gameschedule JOIN team ON "
                           + "(gameschedule.away_team_id = team.team_id OR gameschedule.home_team_id = team.team_id)"
                           + " WHERE team.team_name LIKE '%" + selectedTeamName + "%';";
        ArrayList<Integer> gameIds = new ArrayList<Integer>();
        try {
            ResultSet rs = conn.executeQuery( gameIdSQL );
            while( rs.next() ) {
                gameIds.add( rs.getInt( "game_id" ) );
                conn.executeUpdateQuery( "DELETE FROM gameschedule WHERE game_Id = " + rs.getInt( "game_id" ) );
            }
            for( int curId : gameIds ) {
                conn.executeUpdateQuery( "DELETE FROM game WHERE game_id = " + curId );
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error deleting gameschedule.", null );
            return;
        }

        try {
            sql = "DELETE FROM playsat WHERE team_id = " + teamId;
            int updated = conn.executeUpdateQuery( sql );
            sql = "DELETE FROM team WHERE team_id = " + teamId;
            updated = conn.executeUpdateQuery( sql );
            if( updated > 0 ) {
                JOptionPane.showMessageDialog( rootPane, "The team, any players the team had, "
                                                         + "and any games the team was involved in has been deleted." );
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error deleting game.", null );
        }
        handler.resetAll( 't' );
        searchTeam();
    }//GEN-LAST:event_deleteTeamButtonActionPerformed

    private void deletePlayerButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deletePlayerButtonActionPerformed
        if( !confirmAction( "player", true ) ) {
            return;
        }
        String sql = "DELETE FROM player WHERE player_id = " + selectedPlayerId;
        try {
            int updated = conn.executeUpdateQuery( sql );
            if( updated > 0 ) {
                JOptionPane.showMessageDialog( rootPane, "The player was successfully deleted." );
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error deleting player.", null );
        }
        handler.resetAll( 'p' );
        searchPlayer();
    }//GEN-LAST:event_deletePlayerButtonActionPerformed

    private void deleteGameButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteGameButtonActionPerformed
        if( !confirmAction( "game", true ) ) {
            return;
        }
        String sched_delete = "DELETE FROM gameschedule WHERE game_id = " + selectedGameId;
        try {
            int updated = conn.executeUpdateQuery( sched_delete );
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error trying to delete game schedule", null );
            return;
        }

        String game_delete = "DELETE FROM game WHERE game_id = " + selectedGameId;
        try {
            int updated = conn.executeUpdateQuery( game_delete );
            if( updated > 0 ) {
                JOptionPane.showMessageDialog( rootPane, "Successfully updated this game." );
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error trying to delete game ", null );
            return;
        }
        handler.resetAll( 'g' );
        searchGame();
    }//GEN-LAST:event_deleteGameButtonActionPerformed

    private void addPlayerButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addPlayerButtonActionPerformed
        String playerName = playerNameField.getText();
        String teamName = teamNameField.getText();
        String height = heightField.getText();
        String totalGoalsScored = goalsScoredField.getText();
        String hometown = hometownField.getText();

        int teamId = -1;
        int totalGoals = 0;
        try {
            totalGoals = Integer.parseInt( totalGoalsScored );
            if( totalGoals < 0 ) {
                JOptionPane.showMessageDialog( rootPane, "Total goals needs to be greater than 0." );
                return;
            }
        } catch( NumberFormatException nfe ) {
            JOptionPane.showMessageDialog( rootPane, "Invalid number for total goals scored." );
            return;
        }

        try {
            ResultSet rs = conn.executeQuery( "SELECT Team_id FROM team "
                                              + "WHERE team_name LIKE '%" + teamName + "%'" );
            if( rs.next() ) {
                teamId = rs.getInt( "team_id" );
            } else {
                JOptionPane.showMessageDialog( rootPane, "Team " + teamName + " is not a valid team name." );
                return;
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error trying to insert player " + playerName, null );
            return;
        }

        String sql = "INSERT INTO player (Player_id,Team_id,Name,Height,Goals_scored,Hometown) "
                     + "VALUES (0," + teamId + ",\""
                     + playerName.toUpperCase() + "\",\""
                     + height + "\","
                     + totalGoals + ",\""
                     + hometown + "\")";
        try {
            int updated = conn.executeUpdateQuery( sql );
            if( updated > 0 ) {
                JOptionPane.showMessageDialog( rootPane, "You have successfully inserted a new player." );
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error trying to insert player " + playerName, null );
            return;
        }
    }//GEN-LAST:event_addPlayerButtonActionPerformed

    private void addTeamButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addTeamButtonActionPerformed
        String teamName = teamNameField2.getText();
        String divisionName = divisionNameField.getText();
        String conferenceName = conferenceNameField.getText();
        String homeArenaName = homeArenaNameField.getText();
        String goalsScored = teamGoalsScoredField.getText();
        String goalsScoredAgainst = teamGoalsScoredAgainstField.getText();
        String overtimeWins = overtimeWinsField.getText();
        String points = pointsField.getText();
        String totalLosses = totalLossesField.getText();
        String totalWins = totalWinsField.getText();


        int goals = 0;
        int goalsAgainst = 0;
        int OTWins = 0;
        int pnts = 0;
        int losses = 0;
        int wins = 0;
        int divID = 0;
        int confID = 0;
        int arenaID = 0;
        int teamID = 0;

        try {
            goals = Integer.parseInt( goalsScored );
            goalsAgainst = Integer.parseInt( goalsScoredAgainst );
            OTWins = Integer.parseInt( overtimeWins );
            pnts = Integer.parseInt( points );
            losses = Integer.parseInt( totalLosses );
            wins = Integer.parseInt( totalWins );

            if( goals < 0 || goalsAgainst < 0 || OTWins < 0 || pnts < 0 || losses < 0 || wins < 0 ) {
                JOptionPane.showMessageDialog( rootPane,
                                               "Invalid number entered. Goals scored, goals scored against, overtime "
                                               + "wins, points, losses, and wins should all be non-negative integers" );
                return;
            }
        } catch( NumberFormatException nfe ) {
            JOptionPane.showMessageDialog( rootPane,
                                           "Invalid input. Goals scored, goals scored against, overtime "
                                           + "wins, points, losses, and wins should all be numbers." );
            return;
        }

        try {
            ResultSet rs = conn.executeQuery( "SELECT division_id FROM division "
                                              + "WHERE division_name = '" + divisionName + "'" );
            if( rs.next() ) {
                divID = rs.getInt( "division_id" );
            } else {
                JOptionPane.showMessageDialog( rootPane,
                                               "Division " + divisionName + " is not a valid division name." );
                return;
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error trying to insert team " + teamName, null );
            return;
        }

        try {
            ResultSet rs = conn.executeQuery( "SELECT conference_id FROM conference "
                                              + "WHERE conference_name = '" + conferenceName + "'" );
            if( rs.next() ) {
                confID = rs.getInt( "conference_id" );
            } else {
                JOptionPane.showMessageDialog( rootPane,
                                               "Conference " + conferenceName + " is not a valid conference name." );
                return;
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error trying to insert team " + teamName, null );
            return;
        }


        String sql = "INSERT INTO team (team_id, division_id, conference_id, team_name, overtime_wins, points, "
                     + "goals_scored, goals_scored_against, losses, wins) VALUES ( 0,"
                     + divID + ", " + confID + ", '" + teamName + "', " + OTWins + ", " + pnts + ", "
                     + goals + ", " + goalsAgainst + ", " + losses + ", " + wins + ");";
        try {
            int updated = conn.executeUpdateQuery( sql );
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error trying to insert team " + teamName, null );
            return;
        }

        sql = "INSERT INTO arena (arena_id, name) VALUES (0,'" + homeArenaName + "');";
        try {
            int updated = conn.executeUpdateQuery( sql );
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error trying to insert arena " + homeArenaName, null );
            return;
        }


        try {
            ResultSet rs = conn.executeQuery( "SELECT arena_id FROM arena "
                                              + "WHERE name = '" + homeArenaName + "'" );
            if( rs.next() ) {
                arenaID = rs.getInt( "arena_id" );
            } else {
                JOptionPane.showMessageDialog( rootPane, "Arena " + homeArenaName + " is not a valid arena name." );
                return;
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error trying to query arena " + homeArenaName, null );
            return;
        }

        try {
            ResultSet rs = conn.executeQuery( "SELECT team_id FROM team "
                                              + "WHERE team_name = '" + teamName + "'" );
            if( rs.next() ) {
                teamID = rs.getInt( "team_id" );
            } else {
                JOptionPane.showMessageDialog( rootPane, "Team " + teamName + " is not a valid team name." );
                return;
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error trying to insert arena " + homeArenaName, null );
            return;
        }

        sql = "INSERT INTO playsat (team_id, arena_id) VALUES (" + teamID + ", " + arenaID + ");";

        try {
            int updated = conn.executeUpdateQuery( sql );
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error trying to insert arena " + homeArenaName, null );
            return;
        }
        JOptionPane.showMessageDialog( rootPane, "You have successfully added a team." );

    }//GEN-LAST:event_addTeamButtonActionPerformed

    private void addGameButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addGameButtonActionPerformed
        String awayTeamName = awayTeamNameField.getText();
        String homeTeamName = homeTeamNameField.getText();
        String hostArenaName = hostArenaNameField.getText();
        String datePlayed = gameDatePlayedField.getText();
        String winnerTeamName = winnerTeamNameField.getText();
        String loserTeamName = loserTeamNameField.getText();
        String winnerScore = winnerScoreField.getText();
        String loserScore = loserScoreField.getText();

        int integer_winner_score = 0;
        int integer_loser_score = 0;
        int home_id = -1;
        int away_id = -1;
        int lose_id = -1;
        int arena_id = -1;
        int win_id = -1;
        int game_id = -1;

        try {
            integer_winner_score = Integer.parseInt( winnerScore );
        } catch( NumberFormatException nfe ) {
            JOptionPane.showMessageDialog( rootPane, "Invalid number for winner score." );
            return;
        }
        try {
            integer_loser_score = Integer.parseInt( loserScore );
        } catch( NumberFormatException nfe ) {
            JOptionPane.showMessageDialog( rootPane, "Invalid number for loser score." );
            return;
        }

        String win_id_string = "SELECT team_id FROM team WHERE team_name LIKE '%" + winnerTeamName + "%'";
        try {
            ResultSet rs = conn.executeQuery( win_id_string );
            if( rs.next() ) {
                win_id = rs.getInt( "team_id" );
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error trying to query", null );
            return;
        }

        String home_id_string = "SELECT team_id FROM team WHERE team_name LIKE '%" + homeTeamName + "%'";
        try {
            ResultSet rs = conn.executeQuery( home_id_string );
            if( rs.next() ) {
                home_id = rs.getInt( "team_id" );
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error trying to query", null );
            return;
        }

        String away_id_string = "SELECT team_id FROM team WHERE team_name LIKE '%" + awayTeamName + "%'";
        try {
            ResultSet rs = conn.executeQuery( away_id_string );
            if( rs.next() ) {
                away_id = rs.getInt( "team_id" );
            } else {
                JOptionPane.showMessageDialog( rootPane, "Away team doesn't exist." );
                return;
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error trying to query", null );
            return;
        }

        String lose_id_string = "SELECT team_id FROM team WHERE team_name LIKE '%" + loserTeamName + "%'";
        try {
            ResultSet rs = conn.executeQuery( lose_id_string );
            if( rs.next() ) {
                lose_id = rs.getInt( "team_id" );
            } else {
                JOptionPane.showMessageDialog( rootPane, "Loser team doesn't exist." );
                return;
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error trying to query.", null );
            return;
        }

        String arena_id_string = "SELECT arena_id FROM arena WHERE name LIKE '%" + hostArenaName + "%'";
        try {
            ResultSet rs = conn.executeQuery( arena_id_string );
            if( rs.next() ) {
                arena_id = rs.getInt( "arena_id" );
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error trying to query", null );
            return;
        }

        String sql = "INSERT INTO game (Game_id,Winner_score,Loser_score,Date,Winner,Loser)"
                     + "VALUES (0," + integer_winner_score + "," + integer_loser_score + ",'" + datePlayed
                     + "'," + win_id + "," + lose_id + ")";
        try {
            int updated = conn.executeUpdateQuery( sql );
            if( updated > 0 ) {
                JOptionPane.showMessageDialog( rootPane, "Successfully added game." );
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error trying to insert game", null );
            return;
        }

        String game_id_string = "SELECT game_id FROM game ORDER BY game_id DESC LIMIT 0,1";
        try {
            ResultSet rs = conn.executeQuery( game_id_string );
            if( rs.next() ) {
                game_id = rs.getInt( "game_id" );
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error trying to query", null );
            return;
        }

        String sched_insert = "INSERT INTO gameschedule ( Game_id,Arena_id,Away_team_id,Home_team_id) VALUES ("
                              + game_id + "," + arena_id + "," + away_id + "," + home_id + ")";
        try {
            int updated = conn.executeUpdateQuery( sched_insert );
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error trying to insert game", null );
            return;
        }
    }//GEN-LAST:event_addGameButtonActionPerformed

    private void updatePlayerButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updatePlayerButtonActionPerformed
        String playerName = playerNameField.getText();
        String teamName = teamNameField.getText();
        String height = heightField.getText();
        String totalGoalsScored = goalsScoredField.getText();
        String hometown = hometownField.getText();

        int teamId = -1;
        int totalGoals = 0;
        try {
            totalGoals = Integer.parseInt( totalGoalsScored );
            if( totalGoals < 0 ) {
                JOptionPane.showMessageDialog( rootPane, "Total goals needs to be greater than 0." );
                return;
            }
        } catch( NumberFormatException nfe ) {
            JOptionPane.showMessageDialog( rootPane, "Invalid number for total goals scored." );
            return;
        }

        try {
            ResultSet rs = conn.executeQuery( "SELECT Team_id FROM team "
                                              + "WHERE team_name LIKE '%" + teamName + "%'" );
            if( rs.next() ) {
                teamId = rs.getInt( "team_id" );
            } else {
                JOptionPane.showMessageDialog( rootPane, "Team " + teamName + " is not a valid team name." );
                return;
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error trying to update player " + playerName, null );
            return;
        }

        String sql = "UPDATE player SET name = \"" + playerName + "\", "
                     + "team_id = " + teamId + ", "
                     + "height = \"" + height + "\", "
                     + "goals_scored = " + totalGoalsScored + ", "
                     + "hometown=\"" + hometown + "\" "
                     + "WHERE player_id = " + selectedPlayerId;
        try {
            int updated = conn.executeUpdateQuery( sql );
            if( updated > 0 ) {
                JOptionPane.showMessageDialog( rootPane, "Successfully updated player." );
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error updating player " + playerName, null );
            return;
        }
    }//GEN-LAST:event_updatePlayerButtonActionPerformed

    private void updateTeamButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateTeamButtonActionPerformed
        String teamName = teamNameField2.getText();
        String divisionName = divisionNameField.getText();
        String conferenceName = conferenceNameField.getText();
        String arenaName = homeArenaNameField.getText();
        String goalsScored = teamGoalsScoredField.getText();
        String goalsScoredAgainst = teamGoalsScoredAgainstField.getText();
        String overtimeWins = overtimeWinsField.getText();
        String points = pointsField.getText();
        String totalLosses = totalLossesField.getText();
        String totalWins = totalWinsField.getText();


        int goals = 0;
        int goalsAgainst = 0;
        int OTWins = 0;
        int pnts = 0;
        int losses = 0;
        int wins = 0;
        int divID = 0;
        int confID = 0;
        int arenaID = 0;
        int teamID = 0;

        try {
            goals = Integer.parseInt( goalsScored );
            goalsAgainst = Integer.parseInt( goalsScoredAgainst );
            OTWins = Integer.parseInt( overtimeWins );
            pnts = Integer.parseInt( points );
            losses = Integer.parseInt( totalLosses );
            wins = Integer.parseInt( totalWins );

            if( goals < 0 || goalsAgainst < 0 || OTWins < 0 || pnts < 0 || losses < 0 || wins < 0 ) {
                JOptionPane.showMessageDialog( rootPane, "Invalid number entered. Goals scored, goals scored against, overtime wins, "
                                                         + "points, losses, and wins should all be non-negative integers" );
                return;
            }

        } catch( NumberFormatException nfe ) {
            JOptionPane.showMessageDialog( rootPane, "Invalid number entered. Goals scored, goals scored against, overtime wins, "
                                                     + "points, losses, and wins should all be non-negative integers" );
            return;
        }

        try {
            ResultSet rs = conn.executeQuery( "SELECT division_id FROM division "
                                              + "WHERE division_name = '" + divisionName + "'" );
            if( rs.next() ) {
                divID = rs.getInt( "division_id" );
            } else {
                JOptionPane.showMessageDialog( rootPane, "Division " + divisionName + " is not a valid division name." );
                return;
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error trying to query division " + divisionName, null );
            return;
        }

        try {
            ResultSet rs = conn.executeQuery( "SELECT conference_id FROM conference "
                                              + "WHERE conference_name = '" + conferenceName + "'" );
            if( rs.next() ) {
                confID = rs.getInt( "conference_id" );
            } else {
                JOptionPane.showMessageDialog( rootPane, "Conference " + conferenceName + " is not a valid conference name." );
                return;
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error trying to query conference " + conferenceName, null );
            return;
        }

        String sql = "UPDATE team SET division_id = " + divID + ", conference_id = " + confID + ", team_name ='" + teamName
                     + "', overtime_wins =" + OTWins + ", points = " + pnts + ", goals_scored = " + goals
                     + ", goals_scored_against=" + goalsAgainst + ", losses=" + losses + ", wins=" + wins
                     + " WHERE team_name = '" + selectedTeamName + "';";
        try {
            int updated = conn.executeUpdateQuery( sql );
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error trying to update team " + teamName, null );
            return;
        }

        try {
            ResultSet rs = conn.executeQuery( "SELECT team_id, arena_id FROM team NATURAL JOIN playsat"
                                              + " WHERE team_name='" + selectedTeamName + "'" );
            if( rs.next() ) {
                teamID = rs.getInt( "team_id" );
                arenaID = rs.getInt( "arena_id" );
            } else {
                JOptionPane.showMessageDialog( rootPane, "Team " + teamName + " is not a valid team name." );
                return;
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error trying to query team id for" + teamName, null );
            return;
        }

        sql = "UPDATE arena SET name= '" + arenaName + "' WHERE arena_id = " + arenaID + ";";
        try {
            int updated = conn.executeUpdateQuery( sql );
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error trying to update arena " + arenaName, null );
            return;
        }
        JOptionPane.showMessageDialog( rootPane, "Successfully updated team." );
    }//GEN-LAST:event_updateTeamButtonActionPerformed

    private void updateGameButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateGameButtonActionPerformed
        String awayTeamName = awayTeamNameField.getText();
        String homeTeamName = homeTeamNameField.getText();
        String hostArenaName = hostArenaNameField.getText();
        String datePlayed = gameDatePlayedField.getText();
        String winnerTeamName = winnerTeamNameField.getText();
        String loserTeamName = loserTeamNameField.getText();
        String winnerScore = winnerScoreField.getText();
        String loserScore = loserScoreField.getText();

        int integer_winner_score = 0;
        int integer_loser_score = 0;
        int home_id = -1;
        int away_id = -1;
        int lose_id = -1;
        int arena_id = -1;
        int win_id = -1;

        try {
            integer_winner_score = Integer.parseInt( winnerScore );
        } catch( NumberFormatException nfe ) {
            JOptionPane.showMessageDialog( rootPane, "Invalid number for winner score." );
            return;
        }

        try {
            integer_loser_score = Integer.parseInt( loserScore );
        } catch( NumberFormatException nfe ) {
            JOptionPane.showMessageDialog( rootPane, "Invalid number for loser score." );
            return;
        }

        String win_id_string = "SELECT team_id FROM team WHERE team_name LIKE '%" + winnerTeamName + "%'";
        try {
            ResultSet rs = conn.executeQuery( win_id_string );
            if( rs.next() ) {
                win_id = rs.getInt( "team_id" );
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error trying to query", null );
            return;
        }

        String home_id_string = "SELECT team_id FROM team WHERE team_name LIKE '%" + homeTeamName + "%'";
        try {
            ResultSet rs = conn.executeQuery( home_id_string );
            if( rs.next() ) {
                home_id = rs.getInt( "team_id" );
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error trying to query", null );
            return;
        }

        String away_id_string = "SELECT team_id FROM team WHERE team_name LIKE '%" + awayTeamName + "%'";
        try {
            ResultSet rs = conn.executeQuery( away_id_string );
            if( rs.next() ) {
                away_id = rs.getInt( "team_id" );
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error trying to query", null );
            return;
        }

        String lose_id_string = "SELECT team_id FROM team WHERE team_name LIKE '%" + loserTeamName + "%'";
        try {
            ResultSet rs = conn.executeQuery( lose_id_string );
            if( rs.next() ) {
                lose_id = rs.getInt( "team_id" );
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error trying to query", null );
            return;
        }

        String arena_id_string = "SELECT arena_id FROM arena WHERE name LIKE '%" + hostArenaName + "%'";
        try {
            ResultSet rs = conn.executeQuery( arena_id_string );
            if( rs.next() ) {
                arena_id = rs.getInt( "arena_id" );
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error trying to query", null );
            return;
        }

        String sql = "UPDATE game SET Winner_score = " + integer_winner_score
                     + ", Loser_score = " + integer_loser_score + ", Date = '"
                     + datePlayed + "', Winner = " + win_id + ", Loser = "
                     + lose_id + " WHERE Game_id = " + selectedGameId;
        System.out.println( sql );
        try {
            int updated = conn.executeUpdateQuery( sql );
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error trying to update game", null );
            return;
        }

        String sched_insert = "UPDATE gameschedule SET Arena_id = " + arena_id
                              + ", Away_team_id = " + away_id + ", Home_team_id = "
                              + home_id + " WHERE Game_id = " + selectedGameId;
        System.out.println( sched_insert );
        try {
            int updated = conn.executeUpdateQuery( sched_insert );
            if( updated > 0 ) {
                JOptionPane.showMessageDialog( rootPane, "You have successfully updated this game." );
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error trying to update game schedule", null );
            return;
        }
    }//GEN-LAST:event_updateGameButtonActionPerformed

    /**
     * Matches mm/dd/yyyy
     */
    private boolean checkDate( String date ) {
        return date.matches( "^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.]\\d\\d$" );
    }

    private boolean confirmAction( String type, boolean delete ) {
        if( delete ) {
            int i = JOptionPane.showConfirmDialog( rootPane, "Are you sure you wish to delete this " + type + "?" );
            return (i == JOptionPane.OK_OPTION);
        } else {
            int i = JOptionPane.showConfirmDialog( rootPane, "Are you sure you wish to update this " + type + "?" );
            return (i == JOptionPane.OK_OPTION);
        }
    }

    private JTable getJTable( DefaultTableModel model ) {
        JTable ret = new JTable( model ) {

            @Override
            public boolean isCellEditable( int row, int column ) {
                return false; //Disallow any table editing.
            }
        };
        ret = applyOptions( ret );
        return ret;
    }

    private JTable applyOptions( final JTable table ) {
        table.setRowHeight( 30 );
        table.setRowMargin( 10 );
        table.setSelectionMode( javax.swing.ListSelectionModel.SINGLE_SELECTION );
        table.setShowHorizontalLines( false );
        table.setShowVerticalLines( false );
        return table;
    }

    private void searchPlayer() {
        DefaultTableModel model = new DefaultTableModel();
        model.addColumn( "Player ID" );
        model.addColumn( "Player Name" );
        model.addColumn( "Team Name" );
        String sql = "SELECT * FROM player JOIN team USING (team_id) WHERE player.Name LIKE '%"
                     + searchPlayerField.getText() + "%';";
        try {
            ResultSet rs = conn.executeQuery( sql );
            while( rs.next() ) {
                model.addRow( new Object[]{ rs.getString( "Player_Id" ), rs.getString( "Name" ), rs.getString( "Team_Name" ) } );
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error retrieving player information.", this.getClass() );
        }
        JScrollPane jScrollPane4 = new JScrollPane();
        final JTable table = getJTable( model );
        table.getSelectionModel().addListSelectionListener( new ListSelectionListener() {

            public void valueChanged( ListSelectionEvent lse ) {
                deletePlayerButton.setEnabled( true );
                updatePlayerButton.setEnabled( true );
                //Since the table uses single_selection, there can only be one row selected at a time
                final int curRow = table.getSelectionModel().getLeadSelectionIndex();
                ArrayList<ArrayList<String>> tableData = JTableUtils.dataFromTable( table );
                ArrayList<String> rowData = tableData.get( curRow );
                int playerID = Integer.valueOf( rowData.get( 0 ) );
                setSelectedPlayerId( playerID );
                populatePlayerFields( playerID );
            }
        } );
        jScrollPane4.setViewportView( table );
        playerTableHolder.add( jScrollPane4 );
        jScrollPane4.setBounds( 10, 11, 766, 183 );
        this.repaint();
        this.validate();
    }

    private void searchTeam() {
        DefaultTableModel model = new DefaultTableModel();
        model.addColumn( "Team ID" );
        model.addColumn( "Team Name" );
        model.addColumn( "Division Name" );
        model.addColumn( "Conference Name" );
        String sql = "SELECT * FROM conference JOIN division USING (conference_id)"
                     + " JOIN team USING (division_id) WHERE team.Team_Name LIKE '%"
                     + searchTeamField.getText() + "%';";
        try {
            ResultSet rs = conn.executeQuery( sql );
            while( rs.next() ) {
                model.addRow( new Object[]{ rs.getString( "Team_Id" ),
                                            rs.getString( "Team_Name" ),
                                            rs.getString( "Division_Name" ),
                                            rs.getString( "Conference_Name" ) } );
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error retrieving player information.", this.getClass() );
        }
        JScrollPane jScrollPane2 = new JScrollPane();
        final JTable table = getJTable( model );
        table.getSelectionModel().addListSelectionListener( new ListSelectionListener() {

            public void valueChanged( ListSelectionEvent lse ) {
                deleteTeamButton.setEnabled( true );
                updateTeamButton.setEnabled( true );
                //Since the table uses single_selection, there can only be one row selected at a time
                final int curRow = table.getSelectionModel().getLeadSelectionIndex();
                ArrayList<ArrayList<String>> tableData = JTableUtils.dataFromTable( table );
                ArrayList<String> rowData = tableData.get( curRow );
                String teamName = rowData.get( 1 );
                setSelectedTeamName( teamName );
                populateTeamFields( teamName );
            }
        } );
        jScrollPane2.setViewportView( table );
        teamTableHolder.add( jScrollPane2 );
        jScrollPane2.setBounds( 10, 11, 766, 183 );
        this.repaint();
        this.validate();
    }

    private void searchGame() {
        String awayTeamSQL = "";
        String homeTeamSQL = "";
        String dateSQL = "";
        String gameIdSQL = "";
        DefaultTableModel model = new DefaultTableModel();
        model.addColumn( "Game ID" );
        model.addColumn( "Game Date" );
        model.addColumn( "Home Team" );
        model.addColumn( "Away Team" );
        String search = searchGameField.getText();

        if( search.matches( "[0-9]+.*" ) || search.isEmpty() || search.equals( "" ) ) {
            awayTeamSQL = "SELECT team_name AS Away_Team_Name FROM game NATURAL JOIN gameschedule JOIN team "
                          + "ON gameschedule.away_team_id = team.team_id "
                          + "WHERE Date LIKE '%" + search + "%' ORDER BY game_id";
            homeTeamSQL = "SELECT team_name AS Home_Team_Name FROM game NATURAL JOIN gameschedule JOIN team "
                          + "ON gameschedule.home_team_id = team.team_id "
                          + "WHERE Date LIKE '%" + search + "%' ORDER BY game_id";
            dateSQL = "SELECT date FROM game WHERE Date LIKE '%" + search + "%'";
            gameIdSQL = "SELECT game_id FROM game WHERE Date LIKE '%" + search + "%'";
        } else {
            awayTeamSQL = "SELECT team.team_name AS Away_Team_Name FROM game NATURAL JOIN gameschedule"
                          + " JOIN team ON team.team_id = gameschedule.away_team_id AND game.game_id IN "
                          + "(SELECT game_id FROM game NATURAL JOIN gameschedule JOIN team ON "
                          + "(gameschedule.away_team_id = team.team_id OR gameschedule.home_team_id = team.team_id)"
                          + " WHERE team.team_name LIKE '%" + search + "%') ORDER BY game_id;";
            homeTeamSQL = "SELECT team.team_name AS Home_Team_Name FROM game NATURAL JOIN gameschedule "
                          + "JOIN team ON team.team_id = gameschedule.home_team_id AND game.game_id IN "
                          + "(SELECT game_id FROM game NATURAL JOIN gameschedule JOIN team ON "
                          + "(gameschedule.away_team_id = team.team_id OR gameschedule.home_team_id = team.team_id) "
                          + "WHERE team.team_name LIKE '%" + search + "%') ORDER BY game_id;";
            dateSQL = "SELECT date FROM game NATURAL JOIN gameschedule JOIN team ON "
                      + "(gameschedule.away_team_id = team.team_id OR gameschedule.home_team_id = team.team_id)"
                      + " WHERE team.team_name LIKE '%" + search + "%';";
            gameIdSQL = "SELECT game_id FROM game NATURAL JOIN gameschedule JOIN team ON "
                        + "(gameschedule.away_team_id = team.team_id OR gameschedule.home_team_id = team.team_id)"
                        + " WHERE team.team_name LIKE '%" + search + "%';";
        }

        try {
            ResultSet rs = conn.executeQuery( awayTeamSQL );
            ArrayList<String> awayTeamNames = new ArrayList<String>();
            while( rs.next() ) {
                awayTeamNames.add( rs.getString( "Away_Team_Name" ) );
            }
            rs = conn.executeQuery( homeTeamSQL );
            ArrayList<String> homeTeamNames = new ArrayList<String>();
            while( rs.next() ) {
                homeTeamNames.add( rs.getString( "Home_Team_Name" ) );
            }
            rs = conn.executeQuery( dateSQL );
            ArrayList<String> dates = new ArrayList<String>();
            while( rs.next() ) {
                dates.add( rs.getString( "Date" ) );
            }
            rs = conn.executeQuery( gameIdSQL );
            ArrayList<String> gameIds = new ArrayList<String>();
            while( rs.next() ) {
                gameIds.add( rs.getString( "Game_id" ) );
            }
            for( int i = 0; i < gameIds.size(); i++ ) {
                model.addRow( new Object[]{ gameIds.get( i ),
                                            dates.get( i ),
                                            homeTeamNames.get( i ),
                                            awayTeamNames.get( i ) } );
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "Error retrieving player information.", this.getClass() );
        }
        JScrollPane jScrollPane2 = new JScrollPane();
        final JTable table = getJTable( model );
        table.getSelectionModel().addListSelectionListener( new ListSelectionListener() {

            public void valueChanged( ListSelectionEvent lse ) {
                deleteGameButton.setEnabled( true );
                updateGameButton.setEnabled( true );
                //Since the table uses single_selection, there can only be one row selected at a time
                final int curRow = table.getSelectionModel().getLeadSelectionIndex();
                ArrayList<ArrayList<String>> tableData = JTableUtils.dataFromTable( table );
                ArrayList<String> rowData = tableData.get( curRow );
                int gameId = Integer.valueOf( rowData.get( 0 ) );
                setSelectedGameId( gameId );
                populateGameFields( gameId );
            }
        } );
        jScrollPane2.setViewportView( table );
        gameTableHolder.add( jScrollPane2 );
        jScrollPane2.setBounds( 10, 11, 766, 183 );
        this.repaint();
        this.validate();
    }

    private void populatePlayerFields( int playerID ) {
        String sql = "SELECT * from player JOIN team USING (team_id) where player_id = '" + playerID + "'";

        try {
            ResultSet rs = conn.executeQuery( sql );
            if( rs.next() ) {
                playerNameField.setText( rs.getString( "name" ) );
                teamNameField.setText( rs.getString( "team_name" ) );
                heightField.setText( rs.getString( "height" ) );
                goalsScoredField.setText( rs.getString( "goals_scored" ) );
                hometownField.setText( rs.getString( "hometown" ) );
            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "There was an error retrieving this player's information", null );
        }
    }

    private void populateTeamFields( String teamName ) {
        String sql = "SELECT * FROM team JOIN conference USING (conference_id) "
                     + "JOIN division USING (division_id) "
                     + "JOIN playsat ON team.team_id = playsat.team_id JOIN arena USING (arena_id) "
                     + "WHERE Team_Name = '" + teamName + "'";
        try {
            ResultSet rs = conn.executeQuery( sql );
            if( rs.next() ) {
                teamNameField2.setText( rs.getString( "Team_Name" ) );
                divisionNameField.setText( rs.getString( "division_name" ) );
                conferenceNameField.setText( rs.getString( "conference_name" ) );
                homeArenaNameField.setText( rs.getString( "name" ) );
                overtimeWinsField.setText( rs.getString( "overtime_wins" ) );
                pointsField.setText( rs.getString( "points" ) );
                teamGoalsScoredField.setText( rs.getString( "goals_scored" ) );
                teamGoalsScoredAgainstField.setText( rs.getString( "goals_scored_against" ) );
                totalLossesField.setText( rs.getString( "losses" ) );
                totalWinsField.setText( rs.getString( "wins" ) );

            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "There was an error retrieving this team's information", null );
        }
    }

    private void populateGameFields( int game_id ) {
        String sql = "SELECT "
                     + "(SELECT team_name FROM game NATURAL JOIN gameschedule JOIN team "
                     + "ON gameschedule.away_team_id = team.team_id WHERE game_id = '" + game_id + "')  AS Away_Team_Name,"
                     + "(SELECT team_name FROM game NATURAL JOIN gameschedule JOIN team "
                     + "ON gameschedule.home_team_id = team.team_id WHERE game_id = '" + game_id + "') AS Home_Team_Name, "
                     + "(SELECT team_id FROM game NATURAL JOIN gameschedule JOIN team "
                     + "ON gameschedule.home_team_id = team.team_id WHERE game_id = '" + game_id + "') AS home_id, "
                     + "(SELECT arena.name FROM arena NATURAL JOIN playsat WHERE team_id=home_id) AS arena_name, "
                     + "(SELECT date FROM game WHERE game_id = '" + game_id + "') AS date,"
                     + "(SELECT loser_score FROM game WHERE game_id = '" + game_id + "') AS loser_score,"
                     + "(SELECT winner_score FROM game WHERE game_id = '" + game_id + "') AS winner_score,"
                     + "(SELECT team_name FROM game JOIN team ON team.team_id = game.winner WHERE game_id = '" + game_id + "') AS winner_name,"
                     + "(SELECT team_name FROM game JOIN team ON team.team_id = game.loser WHERE game_id = '" + game_id + "') AS loser_name;";

        try {
            ResultSet rs = conn.executeQuery( sql );
            if( rs.next() ) {
                awayTeamNameField.setText( rs.getString( "Away_Team_Name" ) );
                homeTeamNameField.setText( rs.getString( "Home_Team_Name" ) );
                hostArenaNameField.setText( rs.getString( "arena_name" ) );
                gameDatePlayedField.setText( rs.getString( "date" ) );
                winnerTeamNameField.setText( rs.getString( "winner_name" ) );
                loserTeamNameField.setText( rs.getString( "loser_name" ) );
                winnerScoreField.setText( rs.getString( "winner_score" ) );
                loserScoreField.setText( rs.getString( "loser_score" ) );

            }
        } catch( SQLException sqle ) {
            ExceptionUtils.handleException( this, sqle, "There was an error retrieving this game's information.", null );
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main( String args[] ) {
        java.awt.EventQueue.invokeLater( new Runnable() {

            public void run() {
                new MainClientView().setVisible( true );
            }
        } );
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addGameButton;
    private javax.swing.JButton addPlayerButton;
    private javax.swing.JButton addTeamButton;
    public javax.swing.JTextField awayTeamNameField;
    public javax.swing.JTextField conferenceNameField;
    public final javax.swing.JButton deleteGameButton = new javax.swing.JButton();
    public final javax.swing.JButton deletePlayerButton = new javax.swing.JButton();
    public final javax.swing.JButton deleteTeamButton = new javax.swing.JButton();
    public javax.swing.JTextField divisionNameField;
    private javax.swing.JPanel fieldsHolder;
    private javax.swing.JPanel fieldsHolder1;
    private javax.swing.JPanel fieldsHolder2;
    private javax.swing.JPanel gameActionsHolder;
    public javax.swing.JTextField gameDatePlayedField;
    public javax.swing.JPanel gameTableHolder;
    private javax.swing.JPanel gamesTab;
    public javax.swing.JTextField goalsScoredField;
    public javax.swing.JTextField heightField;
    public javax.swing.JTextField homeArenaNameField;
    public javax.swing.JTextField homeTeamNameField;
    public javax.swing.JTextField hometownField;
    public javax.swing.JTextField hostArenaNameField;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JTabbedPane jTabbedPane1;
    public javax.swing.JTextField loserScoreField;
    public javax.swing.JTextField loserTeamNameField;
    public javax.swing.JTextField overtimeWinsField;
    private javax.swing.JPanel playerActionsHolder;
    public javax.swing.JTextField playerNameField;
    private javax.swing.JPanel playerTab;
    public javax.swing.JPanel playerTableHolder;
    public javax.swing.JTextField pointsField;
    private javax.swing.JButton searchGameButton;
    public javax.swing.JTextField searchGameField;
    private javax.swing.JButton searchPlayerButton;
    public javax.swing.JTextField searchPlayerField;
    private javax.swing.JButton searchTeamButton;
    public javax.swing.JTextField searchTeamField;
    private javax.swing.JPanel teamActionsHolder;
    public javax.swing.JTextField teamGoalsScoredAgainstField;
    public javax.swing.JTextField teamGoalsScoredField;
    public javax.swing.JTextField teamNameField;
    public javax.swing.JTextField teamNameField2;
    public javax.swing.JPanel teamTableHolder;
    private javax.swing.JPanel teamsTab;
    public javax.swing.JTextField totalLossesField;
    public javax.swing.JTextField totalWinsField;
    public final javax.swing.JButton updateGameButton = new javax.swing.JButton();
    public final javax.swing.JButton updatePlayerButton = new javax.swing.JButton();
    public final javax.swing.JButton updateTeamButton = new javax.swing.JButton();
    public javax.swing.JTextField winnerScoreField;
    public javax.swing.JTextField winnerTeamNameField;
    // End of variables declaration//GEN-END:variables
}
